package chabernac.android.wordraster.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class WordRaster {
	private Letter[][] myRaster;
	private String myLanguage;
	private Set<String> myWordsInRaster;

	public WordRaster(){
	}

	public WordRaster(String aLanguage, int aRows, int aColumns){
		myRaster = new Letter[aRows][aColumns];
		myLanguage = aLanguage;
	}

	public int getColumns(){
		return myRaster[0].length;
	}

	public int getRows(){
		return myRaster.length;
	}

	public void setLetter(int aRow, int aColumn, char aLetter){
		myRaster[aRow][aColumn] = new Letter(aLetter, aColumn, aRow);
	}

	public Letter getLetter(int aRow, int aColumn){
		return myRaster[aRow][aColumn];
	}

	public Letter[][] getRaster() {
		return myRaster;
	}


	public List<Letter> getNeighbours(Letter aStartingLetter) {
		List<Letter> theLetters = new ArrayList<Letter>();
		for(int row = aStartingLetter.getRow() -1;row<=aStartingLetter.getRow()+1;row++){
			for(int column = aStartingLetter.getColumn()-1;column<=aStartingLetter.getColumn()+1;column++){
				if(row >=0 && row < getRows() && column>=0 && column <getColumns() && !(row == aStartingLetter.getRow() && column == aStartingLetter.getColumn())){
					theLetters.add(getLetter(row, column));
				}
			}
		}
		return theLetters;
	}

	public String toString(){
		String theRaster = "";
		for(int row=0;row<myRaster.length;row++){
			for(int column=0;column<myRaster[row].length;column++){
				theRaster += myRaster[row][column].getChar();
			}
			theRaster += "\r\n";
		}
		return theRaster;
	}

	public String getLanguage() {
		return myLanguage;
	}

	public Set<String> getWordsInRaster() {
		return myWordsInRaster;
	}

	public void setWordsInRaster( Set<String> aWordsInRaster ) {
		myWordsInRaster = aWordsInRaster;
	}

	public void setRaster(Letter[][] aRaster) {
		myRaster = aRaster;
	}

	public void setLanguage(String aLanguage) {
		myLanguage = aLanguage;
	}
}
